﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SystemControllers.RolesService;
using SystemControllers;
using eTMS.Commons;
namespace eTMS.Controls{
   public class ComboBoxRoles : ComboBoxBindingBase<RolesEntity>
   {
		public ComboBoxRoles(){
	    }
		//Bind data to txtRoles
        public override void BindData(){
		    List<RolesEntity>lsRoles = new List<RolesEntity>(RolesController.ListRolesStatic.ToArray());
			lsRoles=FilterList(lsRoles);
		    if(IsAddChooseItem){
				RolesEntity eChooseItem = new RolesEntity();
				eChooseItem.RoleCode = Constants.CHOOSE_ITEM;
				lsRoles.Insert(0,eChooseItem);
			}		
		    if(IsAddAllItem){
				RolesEntity eChooseItem = new RolesEntity();
				eChooseItem.RoleCode = Constants.APP_ALL;
				lsRoles.Insert(0,eChooseItem);
			}			
		    this.DisplayMember = "RoleCode";
		    object currentSelected=this.SelectedValue;
		    this.ValueMember = "Role_ID";
		    this.DataSource = lsRoles;
		    if(currentSelected==null){
				if(this.Items.Count>0){
					this.SelectedIndex=0;
				}
            }
            else{
					this.SelectedValue = currentSelected;
					if(this.SelectedValue==null){
						if(this.Items.Count>0){
						this.SelectedIndex=0;
					}
                }
            }
        }
	}
}
